import pandas as pd
from sklearn.datasets import load_breast_cancer
# 加载乳腺癌数据集
data = load_breast_cancer()
# 将特征数据和目标数据合并为一个 DataFrame
df = pd.DataFrame(data.data, columns=data.feature_names)
df['target'] = data.target
# 将目标值替换为类别名称
target_names = data.target_names
df['target'] = df['target'].map({0: target_names[0], 1: target_names[1]})
# 导出为 CSV 文件
df.to_csv('breast_cancer.csv', index=False)#具体存储路径
print("数据已成功导出为 breast_cancer.csv 文件！")